package com.reportingapplication.student;

import com.reportingapplication.student.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.res.Configuration;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class DemoActivity extends Activity {

	private EditText window;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_demo);
		window = (EditText) findViewById(R.id.editText1);
		window.setText("Dit is de demo! Kies een lokaal in de buurt:");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.demo, menu);
		return true;
	}

	/**
	 * Reset screen when orientation is changed
	 */
	@Override
	public void onConfigurationChanged(Configuration config){
		super.onConfigurationChanged(config);
		setContentView(R.layout.activity_demo);
	}
	
	public void handleBackPress(View view){
		String windowText = window.getText().toString();
		if(windowText.equals("Dit is de demo! Kies een lokaal in de buurt:")){
			this.finish();
		}else{
			String newText;
			if(windowText.length() == 1 || windowText.length() >= 4){
				newText = "Dit is de demo! Kies een lokaal in de buurt:";
			}else{
				newText = windowText.substring(0, windowText.length()-1);
			}
			window.setText(newText);
		}
	}
	
	public void handleRestartPress(View view){
		window.setText("Dit is de demo! Kies een lokaal in de buurt:");
	}
	
	public void handleOKPress(View view){
		String location = window.getText().toString();
		if(location.equals("Kies een lokaal in de buurt:")){
			Toast.makeText(this, "Vergeet niet een locatie in te vullen.", Toast.LENGTH_LONG).show();
		}else{
			Toast.makeText(this, "Demo afgerond", Toast.LENGTH_SHORT).show();
		}
		//Show message and then finish task
		finish();
	}
	
	public void handleButtonPress(View view){
		Button button = (Button) findViewById(view.getId());
		String windowText = window.getText().toString();
		String inputText = button.getText().toString();
		if(windowText.equals("Dit is de demo! Kies een lokaal in de buurt:")){
			window.setText(inputText);
		} else if(windowText.length() < 3 && inputText.length() == 1){
			window.append(inputText);
		}
	}
}
